#ifndef WORDENGINE_H
#define WORDENGINE_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QTimer>
#include <QLabel>

namespace Ui {
class WordEngine;
}

typedef struct{
    uint8_t item;               /* 病症项 1-7 */
    uint8_t num;                /* 病症对应的条目数 1-n */
    uint8_t confirm_score;      /* 确认病症所需分值  */
}config_info_t;                 /* 病症项  */

typedef struct{
    uint8_t dec;                /* 减去的值 */
    uint8_t min;                /* 最小值 */
    double num;                  /* 比例系数 */
    int ret;                    /* 百分数  */
}mul_info_t;                    /* 疑诊概率  */

typedef struct{
    int set;                    /* 评估结果 0-1  */
    uint8_t score;              /* 评估分数 1-n     */
}score_info_t;                  /* 条目项  */

class WordEngine : public QMainWindow
{
    Q_OBJECT

public:
    explicit WordEngine(QWidget *parent = nullptr); /*初始化界面参数*/
    ~WordEngine();
    void paintEvent(QPaintEvent *);                 /*界面重绘事件*/
    QPixmap resizPic(QString path, int position);   /*调整图片透明度*/
    void on_socket_read(void);                      /*接收来自服务器的验证消息*/
private slots:                                      /*按键对应的具体功能*/
    /*
        按照位置分为 a,b,c,d,e组
            1.on_x_y_z_stateChanged
                如:on_a_1_1_stateChanged,表示a组第一行第一个按键状态发生变化
            2.on_x_y_x_clicked
                如:on_a_1_x_clicked,表示a组无异常按键被按下，执行清除操作

    */

    void on_a_1_1_stateChanged(int arg1);

    void on_a_1_x_clicked();

    void on_a_1_2_stateChanged(int arg1);

    void on_a_1_3_stateChanged(int arg1);

    void on_a_1_4_stateChanged(int arg1);

    void on_a_1_5_stateChanged(int arg1);

    void on_a_2_x_clicked();

    void on_a_2_1_stateChanged(int arg1);

    void on_a_2_2_stateChanged(int arg1);

    void on_a_2_3_stateChanged(int arg1);

    void on_a_3_x_clicked();

    void on_a_3_1_stateChanged(int arg1);

    void on_a_3_2_stateChanged(int arg1);

    void on_a_3_3_stateChanged(int arg1);

    void on_a_4_x_clicked();

    void on_a_4_1_stateChanged(int arg1);

    void on_a_4_2_stateChanged(int arg1);

    void on_a_4_3_stateChanged(int arg1);

    void on_a_4_4_stateChanged(int arg1);

    void on_a_4_5_stateChanged(int arg1);

    void on_b_1_x_clicked();

    void on_b_2_x_clicked();

    void on_b_3_x_clicked();

    void on_b_4_x_clicked();

    void on_b_1_1_stateChanged(int arg1);

    void on_b_1_2_stateChanged(int arg1);

    void on_b_2_1_stateChanged(int arg1);

    void on_b_2_2_stateChanged(int arg1);

    void on_b_3_1_stateChanged(int arg1);

    void on_b_3_2_stateChanged(int arg1);

    void on_b_4_1_stateChanged(int arg1);

    void on_c_1_1_stateChanged(int arg1);

    void on_c_1_2_stateChanged(int arg1);

    void on_c_1_3_stateChanged(int arg1);

    void on_c_1_4_stateChanged(int arg1);

    void on_c_2_1_stateChanged(int arg1);

    void on_c_2_2_stateChanged(int arg1);

    void on_c_2_3_stateChanged(int arg1);

    void on_c_3_x_clicked();

    void on_c_3_1_stateChanged(int arg1);

    void on_c_3_2_stateChanged(int arg1);

    void on_c_4_2_stateChanged(int arg1);

    void on_c_5_1_stateChanged(int arg1);

    void on_c_5_2_stateChanged(int arg1);

    void on_c_5_4_stateChanged(int arg1);

    void on_e_1_1_stateChanged(int arg1);

    void on_e_1_2_stateChanged(int arg1);

    void on_e_1_3_stateChanged(int arg1);

    void on_e_1_4_stateChanged(int arg1);

    void on_e_1_5_stateChanged(int arg1);

    void on_d_1_x_clicked();

    void on_d_1_1_stateChanged(int arg1);

    void on_d_1_2_stateChanged(int arg1);

    void on_d_1_3_stateChanged(int arg1);

    void on_d_1_4_stateChanged(int arg1);

    void on_d_1_5_stateChanged(int arg1);

    void on_bt_clear_clicked();


    void on_c_3_x_stateChanged(int arg1);

    void on_c_4_1_stateChanged(int arg1);

    void on_a_5_x_clicked();

    void on_a_5_1_stateChanged(int arg1);

    void on_a_5_2_stateChanged(int arg1);

    void on_a_5_3_stateChanged(int arg1);

private:
    QLabel *lb_res[7];
    QLabel *lb_cf[7];
    Ui::WordEngine *ui;
    QTcpSocket *socket;
    QTimer *tm ;
    volatile bool is_confirm = false;
    QPixmap img;
    int result[7];
    void update_sta(int item, int index, int sta);
    QString color_t[7];
    mul_info_t mul_t[7] = {
        {6,5,3.7,0},
        {9,8,4.17,0},
        {2,1,16.67,0},
        {5,4,6.67,0},
        {17,16,6.25,0},
        {11,10,4.0,0},
        {17,16,5.88,0},
    };
    const config_info_t config[7] = {
        {1,9,32},
        {2,8,32},
        {3,5,7},
        {4,6,19},
        {5,7,32},
        {6,10,35},
        {7,6,33},
    };
    score_info_t score_t[7][10];
    const score_info_t score[7][10] = {
        {{0,4},
         {0,1},
         {0,13},
         {0,3},
         {0,16},
         {0,13},
         {0,19},
         {0,6},
         {0,13},},
        {{0,5},
         {0,15},
         {0,11},
         {0,15},
         {0,17},
         {0,5},
         {0,14},
         {0,8},},
        {{0,4},
         {0,3},
         {0,10},
         {0,14},
         {0,19},},
        {{0,4},
         {0,2},
         {0,18},
         {0,18},
         {0,9},
         {0,8},},
        {{0,14},
         {0,8},
         {0,10},
         {0,14},
         {0,9},
         {0,10},
         {0,16},},
        {{0,8},
         {0,8},
         {0,17},
         {0,4},
         {0,10},
         {0,6},
         {0,11},
         {0,17},
         {0,21},
         {0,6},},
        {{0,9},
         {0,2},
         {0,10},
         {0,6},
         {0,23},
         {0,10},},
    };
};

#endif // WORDENGINE_H
